package com.lagou.mr.sorttest;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * reduce  输入 k SortBean 输入value：NullWritable
 *输出 k SortBean 输出value：NullWritable
 */
public class SortReduce extends Reducer<SortBean, NullWritable,SortBean,NullWritable> {

    private int index = 1;

    @Override
    protected void reduce(SortBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {

        //默认排序，每次遍历时，都会重新获取一个bean，key已默认排序
        for (NullWritable value : values) {
            key.setIndex(index++);
            context.write(key, NullWritable.get());
        }
    }
}
